import os

os.system("cp ./symbols/sib /usr/share/X11/xkb/symbols")
os.system("cp -r ./sib /usr/share/kf5/locale/countries/")

with open('/usr/share/X11/xkb/rules/evdev.xml', 'r') as f:
    config = f.readlines()

for line in config:
    if "Siberian" in line:
        raise SystemError("Layout is already installed")
    meet = False
    doWrite = False

with open('/usr/share/X11/xkb/rules/evdev.xml', 'w') as f:
    for line in config:
        if doWrite:
            sibConf = "<layout>\n<configItem>\n<name>sib</name>\n<!-- Keyboard indicator for Siberian layouts -->\n\
<shortDescription>sib</shortDescription>\n<description>Siberian</description>\n\
<countryList>\n<iso3166Id>SIB</iso3166Id>\n</countryList>\n<languageList>\n\
<iso639Id>sib</iso639Id>\n</languageList>\n</configItem>\n</layout>\n"
            f.write(sibConf)
            doWrite = False

        if "<layoutList>" in line and not meet:
            doWrite = True
            meet = True
        f.write(line)
        